// pages/shops/record.js
import {
    manager
  } from "../../api/apiData"
  let util = require('../../utils/util.js')
  var pageNum1 = 1; //页码
  Page({
  
    /**
     * 页面的初始数据
     */
    data: {
      loadMoreText: '加载中...', //底部文字
      list: [],
      active: 0,
      show: false,
      currentDate: new Date().getTime(),
      minDate: new Date(2024, 10).getTime(),
      maxDate: new Date().getTime(),
      showDate: '日期搜索',
      showEmail: false,
      email: "",
      start_time: '',
      end_time: ''
    },
  
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      this.getList(1)
  
    },
    onChange(event) {
      this.setData({
        active: event.detail.name
      })
      pageNum1 = 1
      this.setData({
        list: [],
      });
      this.getList(1)
    },
    // 获取列表
    getList(page) {
        let start = util.formatDate(new Date()) + ' ' + '00:00:00'
        let end = util.formatDate(new Date()) + ' ' + '23:59:59'
        if (this.data.active == 1) {
          start = this.data.start_time
          end = this.data.end_time
        }
      var that = this
      manager.order.myList({
        page: page,
        size: 20,
        verification_start_time: start,
        verification_end_time: end
      }, res => {
        that.setData({
          total: res.data.total
        })
        if (res.data.list.length > 0) {
          that.setData({
            list: that.data.list.concat(res.data.list) //合并数据
          })
          if (11 > res.data.list.length > 0) {
            that.setData({
              loadMoreText: '' //没有更多了
            })
          }
  
        } else {
          if (page !== 1) {
            that.setData({
              loadMoreText: '暂无数据'
            })
          } else {
            that.setData({
              list: [],
              loadMoreText: '暂无数据'
            })
          }
        }
        wx.stopPullDownRefresh();
      })
    },
    toShow() {
      this.setData({
        show: true
      })
    },
    formatDate(date) {
      date = new Date(date);
      return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
    },
    onConfirm(event) {
      const [start, end] = event.detail;
      let date = `${this.formatDate(start)} 至 ${this.formatDate(end)}`
      let start_time = this.formatDate(start)
      let end_time = this.formatDate(end)
      console.log(`${this.formatDate(start)} 至 ${this.formatDate(end)}`)
      this.setData({
        showDate: date,
        start_time,
        end_time
      })
      this.onCancel()
      pageNum1 = 1
      this.setData({
        list: [],
      });
      this.getList(1)
      //  let date =  util.formatDateMo(e.detail)
      //  this.setData({
      //   showDate:date
      //  })
      //  this.onCancel()
    },
    onCancel() {
      this.setData({
        show: false
      })
    },
    showE() {
      console.log(this.data.list)
      if (this.data.list.length == 0) {
        wx.showToast({
          title: '暂无记录',
          icon: 'error'
        })
        return false
      }
      this.setData({
        showEmail: true
      })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
  
    },
  
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
  
    },
  
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {
  
    },
  
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {
  
    },
  
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
      pageNum1 = 1
      this.setData({
        list: [],
      });
      this.getList(1)
    },
  
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
      pageNum1 += 1;
      this.getList(pageNum1)
    },
  
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
  
    }
  })